/************************************************************************
 * @file PluginDependencyResolver.h
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#ifndef PLUGINDEPENDENCYRESOLVER_H
#define PLUGINDEPENDENCYRESOLVER_H

#include <QMap>

#include <plugin/plugin/PluginDescription.h>

namespace antu
{
namespace plugin
{
class PluginDependencyResolver
{
public:
    static void resolve(const QString& appGroup,
                        const QString& configPath,
                        vector<PluginDescriptionSharedPtr>& resolvedDescriptions);

    static void checkDependencies(const QString& applicationGroup,
                                  const vector<PluginDescriptionSharedPtr>& descriptions,
                                  const vector<PluginDescriptionSharedPtr>& newDescriptions,
                                  vector<PluginDescriptionSharedPtr>& newDependencies,
                                  vector<PluginDescriptionSharedPtr>& unresolvedPlugins);

    static void reorder(const vector<PluginDescriptionSharedPtr>& descriptions,
                        vector<PluginDescriptionSharedPtr>& sortedDescriptions);

private:

    PluginDependencyResolver();

    static void resolveDependencies(const QString& applicationGroup,
                                    const vector<PluginDescriptionSharedPtr>& descriptions,
                                    vector<PluginDescriptionSharedPtr>& resolvedDescriptions);

    static void checkDependencies(const QString& applicationGroup,
                                  QMap<QString, PluginDescriptionSharedPtr>& sortedPlugins,
                                  vector<PluginDescriptionSharedPtr>& resolvedPlugins,
                                  vector<PluginDescriptionSharedPtr>& unresolvedPlugins);
};

}
}

#endif // PLUGINDEPENDENCYRESOLVER_H
